<% add_decidim_page_title(t(".title")) %>

<% append_javascript_pack_tag "decidim_elections_admin" %>
<% append_stylesheet_pack_tag "decidim_elections_admin" %>

<div class="item_show__header" style="border-bottom: none;">
  <h1 class="item_show__header-title">
    <%= t("decidim.elections.actions.edit") %>
  </h1>

  <div>
    <%= link_to resource_locator(election).path, class: "button button__xs button__transparent-secondary flex flex-row items-center gap-2", target: :blank, data: { "external-link": false } do %>
      <%= icon "eye-line", class: "inline-block" %>
      <%# i18n-tasks-use t("decidim.elections.actions.view") %>
      <%# i18n-tasks-use t("decidim.elections.actions.preview") %>
      <span class="whitespace-nowrap"><%= t(election.published? ? "view" : "preview", scope: "decidim.elections.actions") %></span>
    <% end %>
  </div>
</div>

<%= render "decidim/elections/admin/elections/tabs_menu" %>

<div class="item__edit-form 2xl:mr-80">
  <% if election.published? %>
    <div class="flex flex-col md:flex-row gap-4 w-full mb-10">
      <div class="flex-1"><%= render partial: "decidim/elections/admin/dashboard/status" %></div>
      <div class="flex-1"><%= render partial: "decidim/elections/admin/dashboard/calendar" %></div>
    </div>
    <%= render partial: "decidim/elections/admin/dashboard/results" %>
  <% else %>
    <p class="mb-4"><%= t(".subtitle") %></p>
    <%= render partial: "decidim/elections/admin/dashboard/main" %>
    <%= render partial: "decidim/elections/admin/dashboard/questions" %>
    <%= render partial: "decidim/elections/admin/dashboard/census" %>
  <% end %>
</div>
<% unless election.published? %>
  <div class="item__edit-sticky">
    <div class="item__edit-sticky-container">
      <% if allowed_to?(:publish, :election, election:) %>
        <%= link_to publish_election_path(election),
                    method: :put,
                    class: "button button__sm button__secondary",
                    data: { confirm: t("publish_confirm", scope: "decidim.elections.admin.dashboard") } do %>
                    <%= icon "check-line" %>
                    <%= t("publish", scope: "decidim.elections.admin.elections.form") %>
        <% end %>
      <% end %>
    </div>
  </div>
<% end %>
